package com.yuju.rpt.service.impl;

import com.yuju.common.core.dao.IBaseDao;
import com.yuju.common.core.service.AbstractBaseService;
import com.yuju.exception.BusinessException;
import com.yuju.rpt.dao.ICheckinRoomTypeDao;
import com.yuju.rpt.dao.entity.CheckinRoomType;
import com.yuju.rpt.enums.CheckinRoomTypeReturnEnum;
import com.yuju.rpt.enums.ReportTypeEnum;
import com.yuju.rpt.model.CheckinRoomTypeModel;
import com.yuju.rpt.service.ICheckinRoomTypeService;
import com.yuju.util.Utils;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 *
 * 类名：CheckinRoomTypeServiceImpl  <br />
 *
 * 功能：
 *
 * @author : jiangp <br />
 * @Date : 2018年1月30日 下午3:20:30  <br />
 * @version : 1.1 <br />
 */
@Service
public class CheckinRoomTypeServiceImpl extends AbstractBaseService<CheckinRoomTypeModel, CheckinRoomType, String> implements ICheckinRoomTypeService {
    @Autowired
    private ICheckinRoomTypeDao checkinRoomTypeDao;

    @Override
    public IBaseDao<CheckinRoomTypeModel, CheckinRoomType, String> getDao() {
        // TODO Auto-generated method stub
        return checkinRoomTypeDao;
    }

	/**
	 * 功能:获得按入住类型的入住分析 <br/>
	 * 
	 * 重写：jiaokn <br/>
	 * 
	 * @Date ：2018年2月3日 下午4:22:55<br/>
	 * 
	 * @param checkinRoomTypeModel
	 * @return <br/>
	 * @see com.yuju.rpt.service.ICheckinRoomTypeService#getCheckinStatByRoomType(com.yuju.rpt.model.CheckinRoomTypeModel)
	 */
	@Override
	public List<CheckinRoomTypeModel> getCheckinStatByRoomType(CheckinRoomTypeModel checkinRoomTypeModel) {
		return checkinRoomTypeDao.getCheckinStatByRoomType(checkinRoomTypeModel);
	}

	@Override
	public int saveCheckinStatRpt(Date businessDate) {
		CheckinRoomTypeModel checkinRoomTypeModel = new CheckinRoomTypeModel();
		checkinRoomTypeModel.setBusinessDate(businessDate);
		List<CheckinRoomTypeModel> list = this.getCheckinStatByRoomType(checkinRoomTypeModel);
		for (CheckinRoomTypeModel model : list) {
			model.setId(Utils.getUUID());
			model.setBusinessDate(businessDate);
			model.setBeginTime(businessDate);
			model.setEndTime(new Date(businessDate.getTime() + (long)24*60*60*1000));
			model.setType(ReportTypeEnum.REPORTTYPE_DAY.getValue());
			Date date = new Date();
			model.setGmtCreate(date);
			model.setGmtModified(date);
			if(this.save(model)<1){
				throw new BusinessException(CheckinRoomTypeReturnEnum.CHECKINROOMTYPE_SAVE_FAILURE.getCode(),
						CheckinRoomTypeReturnEnum.CHECKINROOMTYPE_SAVE_FAILURE.getDesc());
			}
			
		}
		return 1;
	}

	@Override
	public CheckinRoomTypeModel getCheckinStatByRoomTypeSum(CheckinRoomTypeModel checkinRoomTypeModel) {
		return checkinRoomTypeDao.getCheckinStatByRoomTypeSum(checkinRoomTypeModel);
	}
	
	
    
    
   

}
